package com.xianxin.testjenkins.controller;

import com.xianxin.testjenkins.annotation.BussinessLog;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 贤心i
 * @version V1.0
 * @Title:
 * @Package com.xianxin.testjenkins
 * @Description: (用一句话描述该文件做什么)
 * @date 2018/5/23 9:58
 **/
@Controller
public class RenderController {

    @BussinessLog("进入首页")
    @GetMapping("")
    public ModelAndView home() {
//        int a = 1 / 0;

        return new ModelAndView("index");
    }

    @BussinessLog("查找名称")
    @GetMapping("/findName")
    @ResponseBody
    public String findName() {
        return "test-jenkins";
    }

    @BussinessLog("根据Id查找")

    @GetMapping("/findById")
    @ResponseBody
    public List<Map<String, Object>> findById() {
        List<Map<String, Object>> list = new ArrayList<>();
        Map<String, Object> person1 = new HashMap<>();
        person1.put("id", 1);
        person1.put("name", "xianxin");
        person1.put("age", 21);
        person1.put("sex", "男");
        list.add(person1);
        return list;
    }

    @BussinessLog("查询所有学生信息")
    @GetMapping("/findAll")
    @ResponseBody
    public List<Map<String, Object>> findAll() {
        List<Map<String, Object>> list = new ArrayList<>();
        Map<String, Object> person1 = new HashMap<>();
        person1.put("id", 1);
        person1.put("name", "xianxin");
        person1.put("age", 21);
        person1.put("sex", "男");
        list.add(person1);
        Map<String, Object> person2 = new HashMap<>();
        person2.put("id", 2);
        person2.put("name", "张三2");
        person2.put("age", 21);
        person2.put("sex", "男2");
        list.add(person2);
        Map<String, Object> person3 = new HashMap<>();
        person3.put("id", 3);
        person3.put("name", "张三3");
        person3.put("age", 21);
        person3.put("sex", "男3");
        list.add(person3);
        Map<String, Object> person4 = new HashMap<>();
        person4.put("id", 4);
        person4.put("name", "张三4");
        person4.put("age", 21);
        person4.put("sex", "男4");
        list.add(person4);
        return list;
    }

}
